package com.xiaoyu.izf.controller;

import cn.hutool.core.util.StrUtil;
import com.xiaoyu.izf.annotation.RequestAuth;
import com.xiaoyu.izf.model.UserInfo;
import com.xiaoyu.izf.model.page.DataTableBean;
import com.xiaoyu.izf.model.page.ParamListBean;
import com.xiaoyu.izf.multivalues.TwoValue;
import com.xiaoyu.izf.service.SerialCommissionLogService;
import com.xiaoyu.izf.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 流水返佣
 */
@RestController
@RequestMapping("/serial_commission")
public class SerialCommissionLogController extends BaseController{

    @Autowired
    private SerialCommissionLogService serialCommissionLogService;
    @Autowired
    private UserInfoService userInfoService;

    @RequestMapping("/list")
    @RequestAuth
    public DataTableBean listData(HttpServletRequest request, @RequestBody String body){
        UserInfo user = user(request);
//        UserInfo user = userInfoService.findByUserName("15208344647");
        ParamListBean paramListBean = getParamListBean(body);
        DataTableBean dataTableBean = serialCommissionLogService.parList(paramListBean,user);

        String strTmp = "实收总额（元）：{}------返佣金额（元）：{}";
        TwoValue<Double,Double> twoValue = serialCommissionLogService.total(paramListBean,user);
        return dataTableBean.setTotalSpace(StrUtil.format(strTmp,twoValue.getValue1(),twoValue.getValue2()));
    }
}
